package com.yuanqi.dz.dc.service.impl;

import pnbclient.helper.StringHelper;
import pnbclient.util.HSClient;
import pnbclient.util.PnbLogFactory;
import pnblog.PnbLogging;

import com.powermop.service.remote.IRefundInforMation;
import com.yuanqi.dz.dc.util.DZConfigRead;
import com.yuanqi.service.DzDataService;
import com.yuanqitech.powermop.dz.DZDataInterface;
import com.yuanqitech.powermop.dz.DZInfo;
import com.yuanqitech.powermop.dz.DZInfoArray;

public class CIBDZServiceImpl implements DZDataInterface{
	public static final PnbLogging LOG = PnbLogFactory.getLogger("DZ_EXT_LOG");

	public static void main(String[] args) {
		DZInfoArray dzInfoArray =new CIBDZServiceImpl().getDZData("898420180620109", "20170418");
	    DZInfo[] d = dzInfoArray.getDzInfo();
	    for (int i = 0; i < d.length; i++) {
			System.out.println(d[i]);
		}
	    System.out.println(d.length);
	
	}

	public DZInfoArray getDZData(String mercharnum, String dzdate) {
		DZInfoArray dzInfoArray = new DZInfoArray();
		String xy_dz_address = DZConfigRead.getProperties("xy_dz_address");
		if (StringHelper.isEmpty(xy_dz_address)) {
			dzInfoArray.setRc("-1");
			dzInfoArray.setErrormsg("获取兴业对账数据HS地址未配置");
			return dzInfoArray;
		}
		LOG.addDebug("create " + IRefundInforMation.class.getSimpleName() + " from:" + xy_dz_address);
		try{
			LOG.addInfo("调用HS接口入参{mercharnum:" + mercharnum + ",dzdate:" + dzdate + "}");
			DzDataService iRefundInforMation = (DzDataService)HSClient.create(DzDataService.class, xy_dz_address);
			dzInfoArray = iRefundInforMation.getDzData(mercharnum, dzdate);
			if (dzInfoArray == null) {
				dzInfoArray = new DZInfoArray();
				dzInfoArray.setRc("-1");
				dzInfoArray.setErrormsg("HS获取兴业对账数据为null");
				return dzInfoArray;
			}
			String rc = dzInfoArray.getRc();
			if ((rc != null) && ("1".equals(rc))) {
				DZInfo[] list = dzInfoArray.getDzInfo();
				if ((list == null) || (list.length == 0)) {
					dzInfoArray = new DZInfoArray();
					dzInfoArray.setRc("-1");
					dzInfoArray.setErrormsg("HS获取兴业对账数据为空");
					return dzInfoArray;
				}

				dzInfoArray = new DZInfoArray();
				dzInfoArray.setRc("1");
				dzInfoArray.setErrormsg("获取兴业对账数据成功!");
				dzInfoArray.setDzInfo(list);
			}
		} catch (Exception e) {
			LOG.addError(e);
			dzInfoArray = new DZInfoArray();
			dzInfoArray.setRc("-1");
			dzInfoArray.setErrormsg("HS获取兴业对账数据异常!");
			return dzInfoArray;
		}

		return dzInfoArray;
	}
}
